#include <iostream>
#include "ThreadPool.h"
#include <memory>
#include <functional>
using std::cout;
using std::endl;
using std::unique_ptr;
using std::function;
using std::bind;

using Elemtype = function<void()>;

class mytask{
public:
    void process(){
        ::srand(::clock());
        int num = ::rand() % 100;
        cout << "in mytask num = " << num  <<endl;
    }
};


void test(){
    unique_ptr<mytask> ptask(new mytask());
    ThreadPool tp(3,6);
    tp.start();
    for(int i=0;i<20;++i){
        cout << "addtask "<< i << " times" << endl;
        Elemtype f = bind(&mytask::process,ptask.get());
        tp.addTask(std::move(f));
    }
    tp.stop();
}
#if 0
void test0(){

    unique_ptr<task> ptask(new mytask());
    ptask->process();
}
#endif

int main()
{
    test();
    return 0;
}
